#pragma once
#include <stddef.h>
#include <stdint.h>

/* 内存分配函数类型 */
typedef void *(*alloc_function)(size_t size);

/* 内存销毁函数类型 */
typedef void (*dealloc_function)(void *);

typedef struct buffer_data_s {
  char *data;
  char *head;
  char *tail;
  size_t opicity;
  struct buffer_data_s *next;
} buffer_data_t;

buffer_data_t *create_buffer_data(alloc_function allocator,
                                  dealloc_function deallocator, size_t opicity);
void free_buffer_data(buffer_data_t *bf_ptr, dealloc_function deallocator);
size_t get_buffer_data_size(buffer_data_t *bf_ptr);
size_t buffer_data_last_size(buffer_data_t *bf_ptr);
char *buffer_data_get(buffer_data_t *bf_ptr, uint64_t index);
void buffer_add_size(buffer_data_t *bf_ptr, size_t value);
size_t buffer_data_find(buffer_data_t *bf_ptr, const char *t, size_t t_size);
int build_buffer_data(buffer_data_t **bf_ptr, size_t size,
                      alloc_function allocator, dealloc_function deallocator,
                      char **build_ret, int *need_release);
int get_buffer(alloc_function allocator, dealloc_function deallocator,
               buffer_data_t *bf, char **ret, size_t *size);